package com.xiaomage.view.draw7

import android.content.Context
import android.graphics.*
import android.view.View

/**
 * Created by Administrator on 2018/1/6.
 */
class DiscretePathEffectPathView(context: Context):View(context) {

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        val paint =getPaint()
        //获取随机路径
        val path=getPath()
        canvas.drawPath(path,paint)

        canvas.translate(0f,200f)
        paint.pathEffect= DiscretePathEffect(2f,5f)
        canvas.drawPath(path,paint)

        canvas.translate(0f,200f)
        paint.pathEffect= DiscretePathEffect(6f,5f)
        canvas.drawPath(path,paint)

        canvas.translate(0f,200f)
        paint.pathEffect= DiscretePathEffect(6f,15f)
        canvas.drawPath(path,paint)


    }

    private fun getPath():Path{
        val path=Path()
        //定义路径起点
        path.moveTo(0f,0f)
        for(i in 0..40){
            path.lineTo(35*i.toFloat(),(Math.random()*100).toFloat())
        }
        return path
    }

    private fun getPaint(): Paint {
        val paint=Paint()
        //设置锯齿
        paint.isAntiAlias=true
        //设置宽度
        paint.strokeWidth=2f
        //设置颜色
        paint.color= Color.parseColor("#448ced")
        //设置填充样式
        paint.style= Paint.Style.STROKE
        return paint
    }
}